package cn.spamc.controller;

import cn.spamc.pojo.SelectInformation;
import cn.spamc.pojo.StudentInformation;
import cn.spamc.pojo.TestPojo;
import cn.spamc.service.impl.SelectInformationServiceImpl;
import cn.spamc.util.JsonMsg;
import com.alibaba.fastjson.JSONObject;
import com.mysql.cj.util.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = "/selectInfo")
public class SelectInformationController {

    @Autowired
    SelectInformationServiceImpl studentInformationService;

    @RequestMapping(value = "/getStudentList", method = RequestMethod.POST)
    @ResponseBody
    public JsonMsg getStudentList(@RequestBody(required = false) String jsonStr)
    {
        System.out.println("已经进入方法体");
        SelectInformation selectInfo = JSONObject.parseObject(StringUtils.safeTrim(jsonStr), SelectInformation.class);
        System.out.println("转换结束");
        System.out.println(selectInfo.toString());
        int offset = (selectInfo.getPageNo()-1) * selectInfo.getPageLimit();
        selectInfo.setPageNo(offset);
        System.out.println(selectInfo.toString());
        List<StudentInformation> studentInformationList = studentInformationService.getStudentListByCondition(selectInfo);
        for(StudentInformation si : studentInformationList)
        {
            System.out.println(si);
        }
        return JsonMsg.success().addInfo("studentInformationList", studentInformationList);
    }

    @RequestMapping(value = "/test")
    @ResponseBody
    public String testConnect()
    {
        return "success";
    }
}
